﻿using System;

namespace Bricks.Injecting
{

    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="TContainerRegistry"></typeparam>
    public abstract class ContainerRegistryFacadeBase<TContainerRegistry> : DisposableFacadeBase<TContainerRegistry>, IContainerRegistryFacade<TContainerRegistry>
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="containerRegistry"></param>
        protected ContainerRegistryFacadeBase(TContainerRegistry containerRegistry) :
            base(containerRegistry)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="service"></param>
        /// <returns></returns>
        public IContainerRegistryFacade Register(Type serviceType, object service)
        {
            return Register(serviceType, string.Empty, service);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="key"></param>
        /// <param name="service"></param>
        /// <returns></returns>
        public abstract IContainerRegistryFacade Register(Type serviceType, string key, object service);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <param name="service"></param>
        /// <returns></returns>
        public IContainerRegistryFacade Register<TService>(TService service)
        {
            return Register<TService>(string.Empty, service);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <param name="key"></param>
        /// <param name="service"></param>
        /// <returns></returns>
        public abstract IContainerRegistryFacade Register<TService>(string key, TService service);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        public IContainerRegistryFacade Register(Type serviceType)
        {
            return Register(serviceType, string.Empty);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public abstract IContainerRegistryFacade Register(Type serviceType, string key);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <returns></returns>
        public IContainerRegistryFacade Register<TService>()
        {
            return Register<TService>(string.Empty);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public abstract IContainerRegistryFacade Register<TService>(string key);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="implType"></param>
        /// <returns></returns>
        public IContainerRegistryFacade Register(Type serviceType, Type implType)
        {
            return Register(serviceType, implType, string.Empty);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="implType"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public abstract IContainerRegistryFacade Register(Type serviceType, Type implType, string key);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <typeparam name="TImpl"></typeparam>
        /// <returns></returns>
        public IContainerRegistryFacade Register<TService, TImpl>() where TImpl : TService
        {
            return Register<TService, TImpl>(string.Empty);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <typeparam name="TImpl"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public abstract IContainerRegistryFacade Register<TService, TImpl>(string key) where TImpl : TService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        public bool IsRegistered(Type serviceType)
        {
            return IsRegistered(serviceType, string.Empty);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public abstract bool IsRegistered(Type serviceType, string key);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <returns></returns>
        public bool IsRegistered<TService>()
        {
            return IsRegistered<TService>(string.Empty);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TService"></typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public abstract bool IsRegistered<TService>(string key);
    }
}
